const fs = require("fs");
const path = require("path");

var msg = ["请输入要创建的文件夹，", "请输入要创建的文件，", "请输入要删除的文件，"];
var index = 0;

console.log(msg[0]);

process.stdin.on("data", (chunk) => {
    var chunk = chunk.toString("utf-8");
    var chunk1 = [];

    if(index == 0){
        chunk1 = chunk.split(" ");
        var name = chunk1[1].slice(0,-2);
        filedirPath = path.join(__dirname, "/" + name);
        fs.mkdir(filedirPath, (err) => {
            if(err){
                return console.error(err);
            }
            else{
                console.log("文件目录创建成功！");
                console.log(msg[index]);
            };
    
        });
        
    }
    else if(index == 1){
        chunk1 = chunk.split(" ");
        var name = chunk1[1].slice(0,-2);
        filePath = path.join(filedirPath, "/" + name);
        fs.writeFile(filePath,"hello node", (err) => {
            if(err){
                console.error(err);
            }
            console.log("文件创建成功！");
            console.log(msg[index]);
        })
    }
    else{
        fs.unlinkSync(filePath);
        console.log("文件删除成功！")
    }
    index ++ ;

})
